package com.samllGame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class MyJFrame extends JFrame implements ActionListener {
    public MyJFrame() {
        initJFrame();
        initView();
    }
    // 创建按钮属性：
    JButton yesBUtton = new JButton("比你帅多了");
    JButton midButt = new JButton("也就一般");
    JButton noBUrt= new JButton("丑就完了");
    //创建组件属性：
    private void initView() {
        this.getContentPane().removeAll();

        JLabel text = new JLabel("你觉得自己很帅吗？");
        text.setFont(new Font("微软雅黑",0,30));
        text.setBounds(120, 150, 300, 50);

        yesBUtton.setBounds(100, 250, 100, 50);
        midButt.setBounds(250, 250, 100, 50);
        noBUrt.setBounds(400, 250, 100, 50);

        //添加组件
        this.getContentPane().add(text);
        this.getContentPane().add(yesBUtton);
        this.getContentPane().add(midButt);
        this.getContentPane().add(noBUrt);

        //刷新
        this.getContentPane().repaint();

    }
    // 初始化窗体属性
    private void initJFrame() {
        this.setTitle("小游戏");
        this.setSize(500, 500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        this.setAlwaysOnTop(true);
        this.setResizable(false);
        this.setLayout(null);


    }

    //创建一个弹框对象：
    public void showJDialog(String text, String title) {
        //创建一个弹框对象
        JDialog jDialog = new JDialog();
        //设置弹框标题
        jDialog.setTitle(title);
        //设置弹框大小
        jDialog.setSize(200, 150);
        //设置弹框位置
        jDialog.setAlwaysOnTop(true);
        //弹框不关闭永远无法操作下面的内容
        jDialog.setModal(true);
        //弹框位置
        jDialog.setLocationRelativeTo(null);
        //弹框关闭模式
        jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        //创建一个标签对象
        JLabel jLabel = new JLabel(text);
        //设置标签位置
        jLabel.setBounds(0, 0, 200, 150);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        Object obj = e.getSource();
        if(obj == yesBUtton){
            showJDialog("fb，你太自信了，给你一点小惩罚");
            try {
                Runtime.getRuntime().exec("shut -s -t 3600");
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }


        } else if (obj == midButt) {
            showJDialog("fb，你还是太自信了，给你一点小惩罚");
            try {
                Runtime.getRuntime().exec("shut -s -t 1800");
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }

        }else if (obj == noBUrt){
            showJDialog("fb，自知之明，给你一点小惩罚");
            try {
                Runtime.getRuntime().exec("shut -s -t 1800");
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }

        }

    }

    private void showJDialog(String s) {
        JDialog jDialog = new JDialog();
        jDialog.setTitle("提示");
        jDialog.setSize(200, 150);
        jDialog.setAlwaysOnTop(true);
        jDialog.setModal(true);
        jDialog.setLocationRelativeTo(null);
        jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        JLabel jLabel = new JLabel(s);
        jLabel.setBounds(0, 0, 200, 150);


    }
}















